package com.fesine.quartz.chapter4;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @description: 自定义排除一小时当中分的值不执行任务
 * @author: Fesine
 * @createTime:2016/11/18 22:42
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/11/18 22:42
 */
public class Listing_4_12 {
    static Log logger = LogFactory.getLog(Listing_4_12.class);

    public static void main(String[] args) {
        new Listing_4_12().startScheduler();
    }

    public void startScheduler() {
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
            schedulerJob(scheduler,PrintJob.class);
            logger.info("scheduler starting up...");
            scheduler.start();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    private void schedulerJob(Scheduler scheduler, Class jobClass) {
        HourlyCalender hc = new HourlyCalender();
        hc.setExcludedMinutes(2);
        hc.setExcludedMinutes(3);
        hc.setExcludedMinutes(5);
        hc.setExcludedMinutes(52);
        try {
            //设置calName值为hourlyCalender
            scheduler.addCalendar("hourlyCalender", hc, true, true);
            Trigger trigger = TriggerUtils.makeImmediateTrigger("myTrigger", -1, 10000);
            //此处set的calName就是上面calName，否则不生效
            trigger.setCalendarName("hourlyCalender");
            JobDetail detail = new JobDetail(jobClass.getName(), Scheduler.DEFAULT_GROUP, jobClass);
            scheduler.scheduleJob(detail, trigger);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
